import nibabel as nib
import numpy as np

# 读取NIfTI文件
filename = r'D:\Astudy\python\feijiang\data\labelsTr\0b2be9e0-886b-4144-99f0-8bb4c6eaa848.nii.gz'
# filename = r'predict_result1\0f593c1e-4bb8-470f-a87b-fee3dbd3b3ed.nii.gz'
nii_img = nib.load(filename)

# 获取数据数组
data = nii_img.get_fdata()
data = np.nan_to_num(data)  # 处理NaN值（如果有）

# 计算类别数量
unique_classes = np.unique(data)
num_classes = len(unique_classes)

print("类别数量:", num_classes)
print("类别列表:", unique_classes)
